<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        //1.对象的引用
        // const info = { name: "yzh", age: 18};
        // const obj = info;
        // info.name = "kobe";
        // console.log(info)       //{name: "kobe", age: 18}
        // console.log(obj)   //{name: "kobe", age: 18}
    </script>

    <script>
        //2. 对象的浅拷贝
        // const info = { name: "yzh", age: 18 , friend: {name: "sabo", height: 1.98}};
        // const obj = Object.assign({}, info);
        // info.name = "kobe";
        // info.friend.name = "jams";

        // console.log(obj)   //这里的obj拷贝不到friend 
        // console.log(info)   

    </script>

    <script>
        // 3.对象的深拷贝
        const info = { name: "yzh", age: 18 , friend: {name: "sabo", height: 1.98}};
        const obj = JSON.parse(JSON.stringify(info));
        info.friend.name = "jams";
        console.log(obj.friend.name) 


        //可以引入第三方库 ladash   _.clone(info) //浅拷贝  _.cloneDeep(info) //深拷贝
    </script>
</body>
</html>